package com.ternnetwork.oa.repository.work;


import com.ternnetwork.oa.entity.work.EventUser;
import com.ternnetwork.oa.entity.work.EventUserId;
import com.ternnetwork.oa.enums.work.ReportType;
import com.ternnetwork.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface EventUserRepository extends BaseRepository<EventUser, EventUserId> {

    @Query("from EventUser t where t.user.id=?1 and t.event.start>=?2 and  t.event.end<?3")
    List<EventUser> findAll(Long userId, Date start, Date end);

    @Query("from EventUser t where t.event.id=?1")
    List<EventUser> findAll(Long eventId);


    @Query("from  EventUser t where t.event.id=:eventId and t.user.id not in(:userIdList)")
    List<EventUser> findAllByEventIdAndExcludeUserIdList(Long eventId, List<Long> userIdList);

    @Modifying
    @Query("delete from EventUser t where t.event.id=:eventId and t.user.id not in(:userIdList)")
    Integer deleteAllByEventIdAndExcludeUserIdList(Long eventId, List<Long> userIdList);

    @Modifying
    @Query("delete from EventUser t where t.event.id=:eventId")
    Integer deleteByEventId(Long eventId);

    @Query("select count(1) from EventUser where user.id=?1 and event.start>?2")
    Long getCount(Long userId,Date start);

}
